package com.hzncc.flowable_diboot.trial_contracts.dto;

import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.diboot.iam.entity.IamOrg;
import com.diboot.iam.entity.IamUser;
import com.hzncc.flowable_diboot.trial_contracts.entity.TrialContractAudit;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* 试用合同审批单 DTO定义
*
* @author MyName
* @version 1.0
* @date 2024-10-16
 * Copyright © MyCorp
*/
@Getter
@Setter
@Accessors(chain = true)
public class TrialContractAuditDTO extends TrialContractAudit  {
private static final long serialVersionUID = 1684457515237526219L;

        /**
        * 合同版本 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "contract_version")
        private Long contractVersionBegin;

        /**
        * 合同版本 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "contract_version")
        private Long contractVersionEnd;
        /**
        * 数量 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "quantity")
        private BigDecimal quantityBegin;

        /**
        * 数量 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "quantity")
        private BigDecimal quantityEnd;
        /**
        * 金额 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "amount")
        private BigDecimal amountBegin;

        /**
        * 金额 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "amount")
        private BigDecimal amountEnd;
        /**
        * 折扣/毛利率 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "discount_or_gross_profit_margin")
        private BigDecimal discountOrGrossProfitMarginBegin;

        /**
        * 折扣/毛利率 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "discount_or_gross_profit_margin")
        private BigDecimal discountOrGrossProfitMarginEnd;
        /**
        * 交货期 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "delivery_period")
        private BigDecimal deliveryPeriodBegin;

        /**
        * 交货期 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "delivery_period")
        private BigDecimal deliveryPeriodEnd;
        /**
        * 试用期限 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "trial_period")
        private Long trialPeriodBegin;

        /**
        * 试用期限 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "trial_period")
        private Long trialPeriodEnd;
        /**
        * 签订部门 关联信息
        */
        @BindQuery(entity = IamUser.class, column = "orgId",condition = "this.principal = id")
        private String dept;
        /**
        * 创建时间
        */
        @BindQuery(comparison = Comparison.GE)
        private LocalDateTime createTime;
        /**
        * 创建时间 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "create_time")
        private LocalDate createTimeBegin;

        /**
        * 创建时间 截止
        */
        @BindQuery(comparison = Comparison.LT, column = "create_time")
        private LocalDate createTimeEnd;
        /**
        * 更新时间
        */
        @BindQuery(comparison = Comparison.GE)
        private LocalDateTime updateTime;
        /**
        * 更新时间 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "update_time")
        private LocalDate updateTimeBegin;

        /**
        * 更新时间 截止
        */
        @BindQuery(comparison = Comparison.LT, column = "update_time")
        private LocalDate updateTimeEnd;

        public LocalDate getCreateTimeEnd() {
            if (getCreateTime() != null) {
                return getCreateTime().plusDays(1).toLocalDate();
            }
            if (createTimeEnd != null) {
                return createTimeEnd.plusDays(1);
            }
            return null;
        }
        public LocalDate getUpdateTimeEnd() {
            if (getUpdateTime() != null) {
                return getUpdateTime().plusDays(1).toLocalDate();
            }
            if (updateTimeEnd != null) {
                return updateTimeEnd.plusDays(1);
            }
            return null;
        }

}